package com.ioudi.digu.dao.support;


import java.util.Date;

import org.hibernate.Query;

public class MessageQuerySupport extends AbstractQuerySupport
{
	protected void createQueryItem(Query query, String key, int index, Object value)
	{
		if(key.equals("timestamp"))
		{
			query.setTimestamp(index, (Date)value);
		}
		else if(key.equals("location"))
		{
			query.setEntity(index, value);
		}
		else if(key.equals("replyID"))
		{
			return;
		}
		else
		{
			query.setString(index, String.valueOf(value));
		}
	}
	
	protected String getStatementItemField(String key)
	{
		if(key.equals("user"))
		{
			return "user.account";
		}
		return key;
	}
	
	protected String getStatementItemOperator(String key, Object value)
	{
		if(key.equals("timestamp"))
		{
			return ">=";
		}
		if(key.equals("replyID"))
		{
			return (Boolean)value ? " is not null" : " is null";
		}
		return "=";
	}
	
	protected boolean isValueSetInStatement(String key)
	{
		return key.equals("replyID");
	}
}
